home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / Chassis 6.0 ƒ / PrintWindowProc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-22  |  4.4 KB  |  130 lines  |  [TEXT/KAHL]

  1. /************************************************************************************/
  2. /*    PrintWindowProc                                                                    */
  3. /************************************************************************************/
  4.  
  5. #include "MyHeaders.h"
  6.  
  7. short PrintWindowProc(short Which)
  8. {
  9.     short            PrintWindRetCode = 0;
  10.     TEHandle    myPrTEH;
  11.     short            outHeight, outLines, outVert, outScroll;
  12.     long        outPageNo;
  13.     
  14.     Rect        IRect;
  15.     Handle        IHandle;
  16.     
  17.     Rect        dlogRect;
  18.     short            rectHeight, rectWidth;
  19.     short            newH, newV;
  20.  
  21.     TPrStatus    prStatus;                        /* status for spooled print        */
  22.     short            tempResRefNum;
  23.     
  24.  
  25.     switch (windTbl[Which].windRec.refCon)        /* Get calling procedure info from    */
  26.         {                                        /* the window table                    */
  27.  
  28.         case (ProcText):                                /* text window procedure    */
  29.             GetPort(&workGrafPtr);                            /* save GrafPort ptr    */
  30.             
  31.             CursorSelect(NIL, NIL, watchCursor);            /* set the cursor        */
  32.             
  33.                                                         /* get "Printing" dialog    */
  34.             myDlogPtr = GetNewDialog (141, NIL, (WindowPtr) -1);
  35.             dlogRect = (*myDlogPtr).portRect;                    /* position on d/t    */
  36.             rectHeight = dlogRect.bottom - dlogRect.top;        
  37.             rectWidth = dlogRect.right - dlogRect.left;
  38.             newH = (screenBits.bounds.right - rectWidth) * .50;    /* centered    horiz.    */
  39.             if (newH < 10)                                        /* not less than 10 */
  40.                 newH = 10;
  41.             newV = ((screenBits.bounds.bottom - 30                /* vert position    */
  42.                      - rectHeight)* (.33)) + 30;                /*   one-third down    */
  43.             if (newV < 30)                                        /* not less than 30    */
  44.                 newV = 30;
  45.             MoveWindow (myDlogPtr, newH, newV, TRUE);            /* move to position    */
  46.             ShowWindow (myDlogPtr);                                /* make visible        */
  47.             
  48.             (**prRecHdl).prJob.pIdleProc= (ProcPtr) myIdleProc;    /* install idleproc    */
  49.             
  50.             prPortPtr = PrOpenDoc(prRecHdl,NIL,NIL);        /* open the document    */
  51.             firstPage = TRUE;
  52.                 
  53.             destRect = (**prRecHdl).prInfo.rPage;            /* printed page size    */
  54.             destRect.top += 42;                                /* lower top for icon    */
  55.             InsetRect (&destRect, 30,30);                    /* dest rect is smaller    */
  56.             
  57.                                             /* compute page scroll amount            */
  58.                                             /* and recompute rect sizes.            */
  59.                                             /* destRect a multiple of lineHeight    */
  60.             outHeight = (**windTbl[Which].windTEH[0]).lineHeight;
  61.             outVert = destRect.bottom - destRect.top;
  62.             outScroll = (outVert / outHeight ) * outHeight;
  63.             destRect.bottom = destRect.top + outScroll;
  64.             
  65.             viewRect = destRect;                        /* viewRect coincides        */
  66.  
  67.             myPrTEH = TENew(&destRect,&viewRect);        /* get TE area for output    */
  68.             
  69.                                                         /* copy font info to output    */
  70.             (**myPrTEH).txFont = (**windTbl[Which].windTEH[0]).txFont;
  71.             (**myPrTEH).txFace = (**windTbl[Which].windTEH[0]).txFace;
  72.             (**myPrTEH).txSize = (**windTbl[Which].windTEH[0]).txSize;
  73.             
  74.                                                             /* point to text        */
  75.             (**myPrTEH).hText = (**windTbl[Which].windTEH[0]).hText;
  76.             
  77.             TECalText(myPrTEH);                                /* reset line begins    */
  78.             
  79.             outPageNo = 0;                                    /* initialize page no    */
  80.             outLines = (**myPrTEH).nLines;                    /* initial # of lines    */
  81.             while ((outLines > 0) && (PrError() == 0))
  82.                 {
  83.                 PrOpenPage (prPortPtr, NIL);                /* open the page        */
  84.                 
  85.                 if (!firstPage)                            /* scroll past prev text    */
  86.                     {
  87.                     if (outLines < (outScroll/outHeight))    /* adjust if < 1 page    */
  88.                         (**myPrTEH).viewRect.bottom =
  89.                                 (**myPrTEH).viewRect.top + (outLines * outHeight);
  90.                         
  91.                     TEScroll(0, -outScroll, myPrTEH);    /* scroll the text            */
  92.                     }
  93.  
  94.                             /****************************************/
  95.                             /*    Draw the icon, or do any other        */
  96.                             /*    graphic or text drawing you want.    */
  97.                             /****************************************/
  98.                 SetRect (&IRect, 0,0, 32,32);                /* draw the icon        */
  99.                 tempResRefNum = CurResFile();
  100.                 UseResFile (myResRefNum);
  101.                 IHandle = GetResource ('ICN#', 128);
  102.                 PlotIcon (&IRect, IHandle);
  103.                 UseResFile(tempResRefNum);
  104.  
  105.  
  106.                 TEUpdate(&viewRect, myPrTEH);                /* draw the text        */
  107.  
  108.                 outLines -= outScroll/outHeight;        /* new # of lines left        */
  109.                 firstPage = FALSE;
  110.  
  111.                 PrClosePage (prPortPtr);                /* close the page            */
  112.                 }
  113.                 
  114.             PrCloseDoc(prPortPtr);                            /* close the document    */
  115.  
  116.             SetPort(workGrafPtr);                            /* restore graf ptr        */
  117.  
  118.             if (((**prRecHdl).prJob.bJDocLoop==bSpoolLoop)        /* if batch            */
  119.                     && (PrError() == 0))
  120.                 {
  121.                 UseResFile (initResRefNum);                        /* for H/P printer    */
  122.                 PrPicFile (prRecHdl,NIL,NIL,NIL,&prStatus);        /* print the spool    */
  123.                 }
  124.  
  125.             DisposDialog(myDlogPtr);                        /* get rid of dlog box    */
  126.         break;
  127.         }
  128.  
  129.     return PrintWindRetCode;
  130. }